#!/usr/bin/ruby -d

require 'sqlite3'
require 'singleton'


class TaskStorage
  include Singleton

  @@dbname = 'tsqlite3.db'
  @@task_table = 't4'

  def initialize
    @db = SQLite3::Database.new( @@dbname )
  end

  def get_pending_tasks(curdate)
    rows = @db.execute( "SELECT id, submitter, subject, date FROM #{@@task_table} WHERE date <= #{curdate} AND pending = 1" )
  end

  def store(subm, subj, date)
    puts "subject #{subj} submitter #{subm} date #{date}"
    @db.execute( "INSERT INTO #{@@task_table} VALUES ( ?, ?, ?, ?, ?)", nil, subm, subj, date, 1 )
  end

  def reset_pending(date)
    @db.execute( "UPDATE #{@@task_table} SET pending = 0 WHERE date = #{date}" )
  end

end
